<template>
  <div id="luckysheet" v-loading="loading" style="margin:0;padding:0;position:absolute;width:100%;top: 0;bottom:0;" />
</template>

<script>
import { previewReport } from '@/api/dev/jmf/jmfReport'

export default {
  props: {
    sheetData: {
      type: Array,
      default: undefined
    }
  },
  data() {
    return {
      loading: false
    }
  },
  mounted() {
    this.preview()
  },
  methods: {
    // 预览
    preview() {
      this.$nextTick(() => {
        this.loading = true
        var language = window.localStorage.getItem('language')
        switch (language) {
          case 'zh_cn':
            language = 'zh'
            break
          case 'en_us':
            language = 'en'
            break
        }
        var sheetData = JSON.parse(localStorage.getItem('sheetData'))
        sheetData.sheetData = JSON.parse(sheetData.sheetData)
        for (let i = 0; i < sheetData.sheetData.length; i++) {
          this.$delete(sheetData.sheetData[i], 'data')
        }
        previewReport(sheetData).then(res => {
          console.log(res.data)
          window.luckysheet.destroy()
          const options = {
            container: 'luckysheet', // 设定DOM容器的id
            title: 'Luckysheet Demo', // 设定表格名称
            lang: language, // 设定表格语言
            plugins: ['chart'],
            autoExpand: true, // 定制化内容
            forceCalculation: true, // 强制刷新公式
            data: res.data,
            showtoolbarConfig: { print: false },
            showinfobar: false // 是否显示顶部信息栏
          }
          // eslint-disable-next-line no-undef
          window.luckysheet.create(options)
          var th = this
          setTimeout(function() {
            th.loading = false
            var allSheets = window.luckysheet.getAllSheets()
            for (let i = allSheets.length - 1; i >= 0; i--) {
              window.luckysheet.setSheetActive(i)
            }
          }, 2000)
        })
      })
    },
    test() {
    }
  }
}
</script>

<style scoped>

</style>
